package com.digitaldreamers.spaceshooter.effect.entitymodifier;

import org.andengine.entity.IEntity;
import org.andengine.entity.modifier.AlphaModifier;
import org.andengine.util.modifier.ease.EaseLinear;
import org.andengine.util.modifier.ease.IEaseFunction;

public class MyAlphaModifier extends AlphaModifier {
	public MyAlphaModifier(final float pDuration, final float pFromAlpha, final float pToAlpha) {
		this(pDuration, pFromAlpha, pToAlpha, null, EaseLinear.getInstance());
	}

	public MyAlphaModifier(final float pDuration, final float pFromAlpha, final float pToAlpha, final IEaseFunction pEaseFunction) {
		this(pDuration, pFromAlpha, pToAlpha, null, pEaseFunction);
	}

	public MyAlphaModifier(final float pDuration, final float pFromAlpha, final float pToAlpha, final IEntityModifierListener pEntityModifierListener) {
		super(pDuration, pFromAlpha, pToAlpha, pEntityModifierListener, EaseLinear.getInstance());
	}

	public MyAlphaModifier(final float pDuration, final float pFromAlpha, final float pToAlpha, final IEntityModifierListener pEntityModifierListener, final IEaseFunction pEaseFunction) {
		super(pDuration, pFromAlpha, pToAlpha, pEntityModifierListener, pEaseFunction);
	}

	protected MyAlphaModifier(final AlphaModifier pAlphaModifier) {
		super(pAlphaModifier);
	}
	
	@Override
	protected void onSetInitialValue(final IEntity pEntity, final float pAlpha) {
		super.onSetInitialValue(pEntity, pAlpha);
		int childCount = pEntity.getChildCount();
		for(int i = 0; i < childCount; i++) {
			IEntity child = pEntity.getChildByIndex(i);
			child.setAlpha(pAlpha);
		}
	}

	@Override
	protected void onSetValue(final IEntity pEntity, final float pPercentageDone, final float pAlpha) {
		super.onSetValue(pEntity, pPercentageDone, pAlpha);
		int childCount = pEntity.getChildCount();
		for(int i = 0; i < childCount; i++) {
			IEntity child = pEntity.getChildByIndex(i);
			child.setAlpha(pAlpha);
		}
	}
}
